import request from '@/utils/request'
import type { ResponseData } from '@/utils/request'

export interface LoginParams {
  account: string
  password: string
  rememberMe: boolean
}

export interface UserInfo {
  id: string
  account: string
  avatar?: string
  email?: string
  roles: string[]
}

/**
 * User login
 * @param data Login parameters
 */
export function login(data: LoginParams) {
  return request<ResponseData<{ token: string,code:number,message:string }>>({
    url: '/user/login/',
    method: 'post',
    data
  })
}

/**
 * Get user info
 */
export function getUserInfo() {
  return request<ResponseData<UserInfo>>({
    url: '/user/info',
    method: 'get'
  })
}

/**
 * User logout
 */
export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

/**
 * Change password
 */
export function changePassword(data: { oldPassword: string; newPassword: string }) {
  return request({
    url: '/user/change-password',
    method: 'post',
    data
  })
} 